#include <iostream>
#include<set>
#include<unordered_map>
using namespace std;

unordered_map<string, set<int>> mp;

int main()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;
		while(x--)
		{
			string s;
			cin >> s;
			mp[s].insert(i);
		}
	}
	int m;
	cin >> m;
	while(m--)
	{
		string s1;
		cin >> s1;
		for(auto& x : mp[s1])
		{
			cout << x << " ";
		}
		cout << endl;
	}
	return 0;
}
